package com.ruoyi.recipes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.recipes.domain.CookTimeOptions;
import com.ruoyi.recipes.service.ICookTimeOptionsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 烹饪时间选项Controller
 * 
 * @author syy
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/recipes/cook_time_options")
public class CookTimeOptionsController extends BaseController
{
    @Autowired
    private ICookTimeOptionsService cookTimeOptionsService;

    /**
     * 查询烹饪时间选项列表
     */
    @PreAuthorize("@ss.hasPermi('recipes:cook_time_options:list')")
    @GetMapping("/list")
    public TableDataInfo list(CookTimeOptions cookTimeOptions)
    {
        startPage();
        List<CookTimeOptions> list = cookTimeOptionsService.selectCookTimeOptionsList(cookTimeOptions);
        return getDataTable(list);
    }

    /**
     * 导出烹饪时间选项列表
     */
    @PreAuthorize("@ss.hasPermi('recipes:cook_time_options:export')")
    @Log(title = "烹饪时间选项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CookTimeOptions cookTimeOptions)
    {
        List<CookTimeOptions> list = cookTimeOptionsService.selectCookTimeOptionsList(cookTimeOptions);
        ExcelUtil<CookTimeOptions> util = new ExcelUtil<CookTimeOptions>(CookTimeOptions.class);
        util.exportExcel(response, list, "烹饪时间选项数据");
    }

    /**
     * 获取烹饪时间选项详细信息
     */
    @PreAuthorize("@ss.hasPermi('recipes:cook_time_options:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cookTimeOptionsService.selectCookTimeOptionsById(id));
    }

    /**
     * 新增烹饪时间选项
     */
    @PreAuthorize("@ss.hasPermi('recipes:cook_time_options:add')")
    @Log(title = "烹饪时间选项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CookTimeOptions cookTimeOptions)
    {
        return toAjax(cookTimeOptionsService.insertCookTimeOptions(cookTimeOptions));
    }

    /**
     * 修改烹饪时间选项
     */
    @PreAuthorize("@ss.hasPermi('recipes:cook_time_options:edit')")
    @Log(title = "烹饪时间选项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CookTimeOptions cookTimeOptions)
    {
        return toAjax(cookTimeOptionsService.updateCookTimeOptions(cookTimeOptions));
    }

    /**
     * 删除烹饪时间选项
     */
    @PreAuthorize("@ss.hasPermi('recipes:cook_time_options:remove')")
    @Log(title = "烹饪时间选项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cookTimeOptionsService.deleteCookTimeOptionsByIds(ids));
    }
}
